<template>
  <div class="audition163">
    <p>方法一：new URL</p>
    <code class="code">
      var url = 'https://foo.com/?id=1&name=tom'<br />
      var _url = new URL(url)<br />
      console.log(_url.searchParams.get('name')) // 'tom'
    </code>
    <p>方法二：split + Map</p>
    <code class="code">
      var url = 'https://foo.com/?id=1&name=tom'<br />
		  var search = 'id=1&name=tom'<br />
      <span class="color3">function</span> <span class="color2">getParam</span>(<span class="color4">str</span>) {<br />
        <span class="indient">// 分割成数组["id=1", "name=tom"]</span><br />
        <span class="indient"><span class="color3">var</span> arr = search.<span class="color2">split</span>('&')</span><br />
        <span class="indient">// 深度分割成Map形式</span><br />
        <span class="indient"><span class="color3">var</span> arr1 = arr.<span class="color2">map</span>(item => {</span><br />
          <span class="indient2"><span class="color">return</span> item.<span class="color2">split</span>('=')</span><br />
        <span class="indient">})</span><br />
        <span class="indient">// 生成map实例</span><br />
        <span class="indient"><span class="color3">var</span> map = new <span class="color3">Map</span>(arr1)</span><br />
        <span class="indient">// 使用map数据类型的get方法</span><br />
        <span class="indient"><span class="color">return</span> map.<span class="color2">get</span>(str)</span><br />
      }
    </code>
  </div>
</template>

<script>
export default {
  name: 'Audition163'
}
</script>

<style>

</style>